package com.example.mall.web.controller;

import com.example.mall.domain.SystemAlerts;
import com.example.mall.dto.SystemAlertsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.SystemAlertsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ISystemAlertsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemAlerts")
public class SystemAlertsController {

    @Autowired
    public ISystemAlertsService systemAlertsService;

    /**
     * 分页查询异常报警记录表信息
     * @param systemAlertsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询异常报警记录表信息",notes = "分页查询异常报警记录表信息",httpMethod = "GET")
    public JSONResult queryPage(SystemAlertsQuery systemAlertsQuery){
        PageDTO<SystemAlertsDto> systemAlertsDtoPageDTO = systemAlertsService.queryPage(systemAlertsQuery);
        return JSONResult.success("查询成功",systemAlertsDtoPageDTO);
    }

    /**
     * 根据id查询异常报警记录表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询异常报警记录表信息",notes = "根据id查询异常报警记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.SYSTEM_ALERTID_NOT_ID);
        }
        SystemAlerts systemAlerts = systemAlertsService.getById(id);
        return JSONResult.success("查询成功",systemAlerts);
    }

    /**
     * 根据id查询异常报警记录表信息
     * @param id
     * @return
     */
    @GetMapping("querySystemAlertsById/{id}")
    @ApiOperation(value = "根据id查询异常报警记录表信息",notes = "根据id查询异常报警记录表信息",httpMethod = "GET")
    public JSONResult querySystemAlertsById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.SYSTEM_ALERTID_NOT_ID);
        }
        SystemAlerts systemAlerts = systemAlertsService.querySystemAlertsById(id);
        return JSONResult.success("查询成功",systemAlerts);
    }

    /**
     * 查询全部异常报警记录表信息
     * @param
     * @return
     */
    @GetMapping("querySystemAlertsList")
    @ApiOperation(value = "查询全部异常报警记录表信息",notes = "查询全部异常报警记录表信息",httpMethod = "GET")
    public JSONResult querySystemAlertsList(){
        List<SystemAlerts> systemAlerts = systemAlertsService.querySystemAlertsList();
        return JSONResult.success("查询成功",systemAlerts);
    }

    /**
     * 新增异常报警记录表
     * @param systemAlertsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增异常报警记录表",notes = "新增异常报警记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody SystemAlertsDto systemAlertsDto){
        systemAlertsService.insert(systemAlertsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改异常报警记录表信息
     * @param systemAlertsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改异常报警记录表信息",notes = "修改异常报警记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody SystemAlertsDto systemAlertsDto){
        systemAlertsService.update(systemAlertsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除异常报警记录表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除异常报警记录表信息",notes = "删除异常报警记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        systemAlertsService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除异常报警记录表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除异常报警记录表信息",notes = "批量删除异常报警记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        systemAlertsService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
